﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data;
using MySql.Data.MySqlClient;

namespace Stat1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btn_Load_Click(object sender, EventArgs e)
        {
            string connectionString = @"server=b.npx.cz;User Id=tota;Password=jAnca639;database=tota";
            string command01 = @"SELECT id, name, id_uppercat, comment, dir, rank, site_id, status, visible, representative_picture_id, uppercats, commentable, global_rank, image_order, permalink FROM pwg_categories";
            MySql.Data.MySqlClient.MySqlConnection mySqlConnection = new MySqlConnection(connectionString);
            MySql.Data.MySqlClient.MySqlCommand mySqlCommand = new MySqlCommand(command01,mySqlConnection);


            mySqlConnection.Open();
            
            MySql.Data.MySqlClient.MySqlDataAdapter mySqlDataAdapter = new MySqlDataAdapter(mySqlCommand);

            DS_ToTa.Tables.Add("Kategorie");               
            dataGridView1.DataSource = DS_ToTa;
            dataGridView1.DataMember = "Kategorie";
            DS_ToTa.Tables["KAtegorie"].BeginLoadData();
            mySqlDataAdapter.Fill(DS_ToTa.Tables["Kategorie"]);
            DS_ToTa.Tables["KAtegorie"].EndLoadData();
            mySqlConnection.Close();

            foreach (DataRow data in DS_ToTa.Tables["Kategorie"].AsEnumerable())
            {
                int? parrent_id = (int?)data["id_uppercat"];
                Console.WriteLine(parrent_id==null?"Nic":parrent_id.ToString());
            }

        }
    }
}
